#include <iostream>
#include <execinfo.h>
#include <exception>
#include <string>
/*
 * g++ -rdynamic backtrace.cc
 * ./a.out
 * call stack will be shown
 */
using namespace std;
class MyException:public exception
{
    public:
    MyException()
    {
        void *trace[20];
        int count=backtrace(trace,10);
        char **string=backtrace_symbols(trace,count);
        int i=0;
        for(i=0;i<count;i++){
            cout<<string[i]<<endl;
        }
    }
};
void throw_test()
{
    cout<<"start throw"<<endl;
    throw MyException();
}
int main()
{
    cout<<"this is backtrace test"<<endl;
    try{
        throw_test();
    }catch(exception e){
        cout<<"catched"<<endl;
    }
}
